﻿using System.Collections.Generic;
using SpecialEffects;
using Microsoft.Xna.Framework;
using DrawableObjects.Actors.Weapons;
using InterfaceComponents;

namespace DrawableObjects.Actors.Aircrafts 
{
    /// <summary>
    /// This class represents all aircrafts which have several specialeffects and are
    /// instantiated by static methods with given values and a private constructor.
    /// These aircrafts are the player ship, drone and boss.
    /// </summary>
    public class SpecialEffectsAircraft : Aircraft
    {

        public BasicFireAndSmoke fireTrail
        {
            get;
            set;
        }

        public BasicFireAndSmoke smokeTrail
        {
            get;
            set;
        }

        private Vector3 fireSmokeTrail_offset
        {
            get;
            set;
        }

        private bool hasFireSmokeTrail
        {
            get;
            set;
        }

        public bool hasDamageSmoke
        {
            get;
            set;
        }

        public BasicFireAndSmoke damageSmoke;

        public override void collide(Actor actor2)
        {
            base.collide(actor2);
        }

        //creates a player airship
        public static SpecialEffectsAircraft GET_PLAYER_SHIP(Matrix worldMatrix)
        {
            HUDWrapper<int> health = new HUDWrapper<int>(new List<HUDComponent>());
            health.value = 150;
            Weaponsystem[] weaponsystems = new Weaponsystem[3] 
            { 
               Weaponsystem.GET_WEAPON_PLAYER_MISSILE(new Vector2[2]{new Vector2(-10, 0), new Vector2(10, 0)}),
               Weaponsystem.GET_WEAPON_PLAYER_PLASMA(new Vector2[1]{new Vector2(0, 0)}),
               Weaponsystem.GET_WEAPON_PLAYER_LASER(new Vector2[2]{new Vector2(-6, -16), new Vector2(6, -16)})
            };
            weaponsystems[0].launchAngles = new float[2] { -0.45f, 0.45f };
            return new SpecialEffectsAircraft(weaponsystems, 0, null, health, "aircraft_player", worldMatrix, 0.01875f, 1, true, new Vector3(0, 0, 15));
        }


        //creates a drone airship
        public static SpecialEffectsAircraft GET_DRONE(Matrix worldMatrix)
        {
            HUDWrapper<int> health = new HUDWrapper<int>(new List<HUDComponent>());
            health.value = 10;
            Weaponsystem[] weaponsystems = new Weaponsystem[2] 
            { 
               Weaponsystem.GET_WEAPON_PLAYER_LASER(new Vector2[1]{new Vector2(0, 0)}),
               Weaponsystem.GET_WEAPON_HEALER(new Vector2(0, 0))
            };
            SpecialEffectsAircraft drone = new SpecialEffectsAircraft(weaponsystems, 0, null, health, "aircraft_drone", worldMatrix, 0.025f, 1, false, Vector3.Zero);
            drone.speed = 0.5f;
            return drone;
        }
        //creates a boss airship
        public static SpecialEffectsAircraft GET_BOSS(Matrix worldMatrix)
        {
            Weaponsystem[] weaponsystems = new Weaponsystem[5] 
            { 
               Weaponsystem.GET_WEAPON_BOSS_LIGHTNING(new Vector2(0, 70)),
               Weaponsystem.GET_WEAPON_BOSS_MISSILE(new Vector2[5]{new Vector2(5,-10),new Vector2(5,-5),new Vector2(5,0),new Vector2(5,5),new Vector2(5,10)}),
               Weaponsystem.GET_WEAPON_BOSS_MISSILE(new Vector2[5]{new Vector2(-5,-10),new Vector2(-5,-5),new Vector2(-5,0),new Vector2(-5,5),new Vector2(-5,10)}),
               Weaponsystem.GET_WEAPON_BOSS_LASER(new Vector2[2]{new Vector2(7,55),new Vector2(-7,55)}),
               Weaponsystem.GET_WEAPON_BOSS_SONARWAVE(new Vector2(0,40))
            };
            weaponsystems[2].launchAngles = new float[5] { 1.2f, 1.0f, 0.8f, 0.6f, 0.4f };
            weaponsystems[1].launchAngles = new float[5] { -1.2f, -1.0f, -0.8f, -0.6f, -0.4f };
            HUDWrapper<int> health = new HUDWrapper<int>(new List<HUDComponent>());
            health.value = 3000;
            SpecialEffectsAircraft boss = new SpecialEffectsAircraft(weaponsystems, 300, null, health, "aircraft_boss", worldMatrix, 6.5f, 0.3f, false, Vector3.Zero);
            boss.speed = 0.8f;
            return boss;
        }

        /// <summary>
        /// Sets the position and direction of the aircrafts' fire- and smoketrail.
        /// </summary>
        public override void Update()
        {
            base.Update();
            if (hasFireSmokeTrail)
            {
                fireTrail.SetPosition(worldMatrix.Translation + fireSmokeTrail_offset);
                fireTrail.SetDirection(Vector3.Backward);
                smokeTrail.SetPosition(worldMatrix.Translation + fireSmokeTrail_offset);
                smokeTrail.SetDirection(Vector3.Backward);
                fireTrail.Update();
                smokeTrail.Update();
            }

            if (hasDamageSmoke)
            {
                damageSmoke.SetPosition(worldMatrix.Translation);
                damageSmoke.Update();
            }
        }

        private SpecialEffectsAircraft(Weaponsystem[] weaponsystems, int killScore, Item dropItem, HUDWrapper<int> health, string strModel, Matrix worldMatrix, float scaleFactor, float boundingFactor, bool hasFireSmokeTrail, Vector3 fireSmokeTrail_offset)
            : base(weaponsystems, killScore, dropItem, health, strModel, worldMatrix, scaleFactor, boundingFactor)
        {
            this.hasFireSmokeTrail = hasFireSmokeTrail;
            this.fireSmokeTrail_offset = fireSmokeTrail_offset;
            smokeTrail = BasicFireAndSmoke.CreateSmokeTrail_PlayerShip();
            fireTrail = BasicFireAndSmoke.CreateFireTrail_PlayerShip();
            hasDamageSmoke = false;
        }

        public override void Initialize()
        {
            base.Initialize();
            world.addSpecialEffect(smokeTrail);
            world.addSpecialEffect(fireTrail);
        }

    }
}

